local httparg    = require("shared.api.httparg")
local response   = require("shared.api.response")
local def        = require("shared.api.def")
local tag        = httparg.tag()
local assertion  = httparg.assertion


local ARGS = {
  -- exist body?
  tag.body('json', 'required'),

  username   = tag.json.username  ('string', 'required', assertion.non_empty_string()),
  alliance   = nil,
  bonus_type = nil,
}

-- set alliance and bonus_type
do
  ARGS.alliance   = "muse"
  ARGS.bonus_type = "reload_bonus"
end


local RESULT
do
  local walletapi = require("shared.api.wallet-api")

  local reply, err = walletapi.account.peek_reload_bonus(
      {
        username    = ARGS.username,
        alliance    = ARGS.alliance,
        bonus_type  = ARGS.bonus_type,
      })

  if err then
    response.error(err)
  end

  if not reply or #reply.content == 0  then
    response.error(def.ERROR_CODE.NO_CONTENT)
  end

  -- export
  RESULT = reply
end

-- response
response.success(RESULT)
